package com.multimedia.scala.euler
/*
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91  99.

Find the largest palindrome made from the product of two 3-digit numbers.
 */
object Asd4 {
  def main(args : Array[String]) : Unit = {
    def isPalindrome(x: Int): Boolean = {
      var y = x.toString.toCharArray
      if (y.length%2==1) return false
      var (p1, p2) = y.splitAt(y.length/2)
      p1.corresponds(p2.reverse){_ == _}
    }
    var res = scala.collection.mutable.ListBuffer[Int]()
    (100 to 999).foreach(x=>{
      (100 to 999).foreach(y=>{
        if (isPalindrome(x*y)) res+=x*y
      })
    })
    println(res.max)
  }
}
